package P037_ConstructionCodeCanDo;

import org.junit.Test;

/**
 * @ClassName : ConstructionCodeCanDo
 * @Description : 构造代码块会想你所想
 * @Author : wukj1
 * @Date: 2022/3/8 15:38
 **/
public class ConstructionCodeCanDo {

    @Test
    public void test(){
        new Base();
        new Base("123");
        new Base(1);
        //如果遇到this关键字（也就是构造函数调用自身其他构造函数时），则不插入构造代码块
        System.out.println(Base.returnNumberOfObjects());
    }

}

class Base{
    private static int numberOfObjects = 0;

    {
        numberOfObjects++;
    }

    public Base(){

    }

    public Base(String _str){
        this();
    }

    public Base(int _i){

    }

    public static int returnNumberOfObjects(){
        return numberOfObjects;
    }
}
